#include "BarSectionNumericalCalculator.h"

#include <algorithm>
#include <vector>

#include "DataStructure/Common/Real.h"
#include "SectionCalculator/StandardSectionTool.h"

using SG::Algebra::Point;
using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::FEMSolver::Element::BarSectionNumericalCalculator;

void BarSectionNumericalCalculator::Mesh (const PBARLData& section, _OUT Meshes& meshes, int refineLevel) const
{
    Real b{ section.m_dimension[0] };
    Real h{ section.m_dimension[1] };

    std::vector<Real> edge{ b, h };
    Real              meshSize = *min_element (edge.begin (), edge.end ()) / (refineLevel + 2);
    int               nb       = int (b / meshSize);
    int               nh       = int (h / meshSize);

    StandardSectionTool secMesh;
    Point               point;
    int                 nodeId{ 0 };
    int                 eleId{ 0 };
    NodeSet             newEdgeNodes;

    point.m_y = -0.5 * b;
    point.m_z = -0.5 * h;
    secMesh.MeshRect (point, b, h, nb, nh, nodeId, eleId, _OUT meshes, _OUT newEdgeNodes);
}